<?php
/**
 * Created by PhpStorm.
 * User: gyccvvh
 * Date: 2018-06-14
 * Time: 14:40
 */
namespace app\merchant\validate;
use think\Validate;

class Merchant extends Validate
{
    protected $rule = [
        'username|用户名'  => 'require|max:64|min:6|unique:merchant',
        'password|密码'    => 'require|max:25|min:6',
        'email|邮箱'        => 'email|require|unique:merchant',
        'mobile|手机号'    => 'mobile:mobile|unique:merchant',
    ];
    protected $message = [
        'username.require'  => '用户名不能空',
        'username.max'      => '用户名最大长度为64',
        'username.min'      => '用户名最小长度为6',
        'password.require'  => '密码不能为空' ,
        'password.min'      => '密码最小长度为6',
        'password.max'      => '密码最大长度为25',
        'email.require'  => '邮箱不能为空',
        'username.unique'   => '用户名已注册，请重试',
        'email.unique'  => '邮箱已注册，请重试',
        'mobile.unique' => '手机已被注册，请重试'
    ];

    protected $scene = [
        'login' => ["password"],
        'register'  => ['username','password','email','mobile']
    ];

    // 自定义手机验证规则
    protected function mobile($value, $rule, $data)
    {
        $res = okay_ismobile($value);
        return $res == true ? true : "手机号错误";
    }
}